<script setup>
import baseModel from "@/components/baseModel/baseModel.vue";
import { computed, onMounted, reactive, ref, nextTick, watch } from "vue";

import { message } from "ant-design-vue";

import { } from "@ant-design/icons-vue";

const dialog = ref(null);

const emit = defineEmits(["timerOver:data"]);

const overTime = ref(6);
const intervalId = ref(null);

const timerRunStart = () => {
  intervalId.value = setInterval(() => {
    overTime.value--;
    if (overTime.value <= 0) {
      clearInterval(intervalId.value);
      emit("timerOver", 'view');
    }
  }, 1000);
};

const closeModal = (type = 'emit', mode = 'view') => {
  clearInterval(intervalId.value);
  // 增加emit 判断, 避免死循环
  type == 'emit' && emit("timerOver", mode)
  dialog.value.closeModal();
};

const showModal = () => {
  overTime.value = 6;
  timerRunStart();
  dialog.value.showModal();
};

defineExpose({
  showModal,
  closeModal,
});
</script>

<template>
  <div class="audition">
    <!-- 
      :title="null"

     -->
    <baseModel ref="dialog" :contentWidth="'554px'" minWidth="554px" :zIndex="9999"
      :getContainer="() => document.queryselector('.audition')" :closable="false" :maskClosable="false">
      <template #title>
        <div></div>
      </template>
      <template #content>
        <div class="content">
          <img src="@/views/shotstack/components/dialogComponent/img/loading.gif" class="title_img" alt="" />
          <p>已提交成功</p>
          <span>生成时间预计2-5分钟</span>
        </div>
      </template>
      <template #footer>
        <div class="bottom">
          <a-button class="btn" key="submit" @click="closeModal('emit', 'keep')">继续合成视频</a-button>
          <a-button class="btn" key="submit" type="primary" @click="closeModal('emit', 'view')">查看合成记录({{ overTime
            }}s)</a-button>
        </div>
      </template>
    </baseModel>
  </div>
</template>

<style lang="less" scoped>
.title_box {
  span {
    font-size: 18px;
    color: #0c0d0e;
  }
}

.content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 20px;

  .loding {
    margin-top: 50px;
  }

  .title_img {
    width: 120px;
    height: 120px;
    object-fit: contain;
  }

  p {
    font-weight: 600;
    font-size: 16px;
  }

  span {
    color: #888;
  }
}

.bottom {
  display: flex;

  .btn {
    margin-left: auto;
  }
}
</style>
